<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta charset="UTF-8">
		<title>自动投资_共富网_Gofull.com.cn</title>
		<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>		
		<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
		<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
	</head>
	<body>
		<div id="wrap">
			<div class="myFace"><img src="/v3/images/circle_bg1.png" /></div>
			<div class="mySum">
				<p>可用余额</p>
				<p class="mMoney">￥<fmt:formatNumber value="${session.user.usableSum }" pattern="#,##0.00#"/></p>	
			</div>
			<ul class="autoItem">
				<li>
					<span class="at-title">借款期限上限：</span>
					<div class="at-box">					
						<s:select list="#{-1:'1天',-15:'15天',-25:'25天',1:'1个月',2:'2个月',3:'3个月',4:'4个月',5:'5个月',6:'6个月',7:'7个月',8:'8个月',9:'9个月',10:'10个月',11:'11个月',12:'12个月',18:'18个月',24:'24个月',30:'30个月',36:'36个月'}" id="deadlineEnd" 
            						cssClass="select" listKey="key" listValue="value" value="#request.automaticBidMap.deadlineEnd"></s:select>
						
						<div class="selcBG">
							<i class="icon-selcItem"></i>
						</div>
					</div>
				</li>
				<li>
					<span class="at-title">年化利率下限：</span>
					<div class="at-box">
						<input class="input" id="rateStart" maxlength="20" value="${automaticBidMap.rateStart}" type="text">
						<div class="selcBG">
							%
						</div>
					</div>
				</li>
				<li>
					<span class="at-title">账户保留金额：</span>
					<div class="at-box">
						<input class="input" id="remandAmount" maxlength="20" value="${automaticBidMap.remandAmount }" type="text">
						<div class="selcBG">
							元
						</div>
					</div>
				</li>
			</ul>
			<div class="Nxt-btn">
				<s:if test="#request.automaticBidMap.bidStatus == 2">
					<%-- <a class="light-blue" href="javascript:openAutoBid();">保存设置</a> --%>
					<a id="closeBtn" <%--class="light-gray"--%> href="javascript:closeAutoBid();">关闭自动投资</a>
				</s:if>
				<s:else>
					<a id="openBtn" href="javascript:openAutoBid();">开启自动投资</a>
				</s:else>
			</div>
		</div>
		<jsp:include page="/include/v3/footer.jsp"></jsp:include>

<script type="text/javascript" src="/v3/js/showts.js"></script>
<script>
$(window).load(function() {
	var aiW=$(".autoItem").width();
	var atW=$(".at-title").width();
	var slW=$(".selcBG").width();	
	$(".at-box").width(aiW-atW-2);
	$(".input").width(aiW-atW-slW-23); 	
	$(window).resize(function(){
		myWindowResize();
	})
	function myWindowResize(){
	var aiW=$(".autoItem").width();
	var atW=$(".at-title").width();
	var slW=$(".selcBG").width();	
	$(".at-box").width(aiW-atW-2);
	$(".input").width(aiW-atW-slW-23); 	
	}
});

function openAutoBid(){
	var param = {};
    param["paramMap.rateStart"] = $('#rateStart').val();
    param["paramMap.deadlineEnd"] = $('#deadlineEnd').val();
    param["paramMap.remandAmount"] = $('#remandAmount').val();

    //异步请求
   $.ajax({
      		type: 'POST',
      		url: "/wchatAutomaticBidModify.do",
      		data: param,
      		beforeSend: function() {
                  $("#openBtn").attr("href","javascript:;").html("开启中...");
              },
      		success: function(data) {
      			if(data.msg == '操作成功'){
      				//操作成功，刷新页面
      				window.location.href = "/wchatAutoInvestInit.do";
      			}else{
      				showAlert(data.msg);
      				$("#openBtn").attr("href","javascript:openAutoBid();").html("开启自动投资");
      				
      			}
      		}
	});
}

function closeAutoBid(){
	var param = {};

    //异步请求
   $.ajax({
      		type: 'POST',
      		url: "/wchatAutomaticBidClose.do",
      		data: param,
      		beforeSend: function() {
                  $("#closeBtn").attr("href","javascript:;").html("关闭中...");
              },
      		success: function(data) {
      			if(data.msg == '操作成功'){
      				//操作成功，刷新页面
      				window.location.href = "/wchatAutoInvestInit.do";
      			}else{
      				showAlert(data.msg);
      				$("#closeBtn").attr("href","javascript:openAutoBid();").html("关闭自动投资");
      				
      			}
      		}
	});
}
</script>
</body>
</html>
